<template>
    <div class="goodsdetail">
        <head-top head-title="" go-back='true'></head-top>
        <section class="goodsdetail_container">
            <ul class="sellerinfo">
                <li class="selleravatar"><img :src="goodDetailData.selleravatar"/></li>
                <li class="sellername">{{ goodDetailData.sellername }}</li>
            </ul>
            <hr>
            <ul class="goodinfo">
                <li class="goodprice">
                    <span>￥{{ goodDetailData.goods_price }}</span>
                </li>
                <li class="gooddesc"><p>
                    {{ goodDetailData.goods_brief }}
                </p>
                </li>
            </ul>
            <ul class="good_image_container">
                <section v-for="item in goodDetailData.images" :key="item">
                    <img :src="item.image" class="goodimage">
                </section>
            </ul>
        </section>
        <section class="buyfoot">
            <router-link
                    :to="{path: 'chat', query:{sellername:goodDetailData.sellername}}">
                <img src="../../images/chat.png">
            </router-link>
            <router-link
                    :to="{path: 'buy', query:{ gooddetail:goodDetailData}}"
                    class="buybutton">
                <span>我想买</span>
            </router-link>
        </section>
    </div>
</template>

<script>
    import {mapState, mapMutations} from 'vuex'
    import {goodDetails} from 'src/service/getData'
    import loading from 'src/components/common/loading'
    import {loadMore, getImgPath} from 'src/components/common/mixin'
    import {imgBaseUrl} from 'src/config/env'
    import headTop from 'src/components/header/head'

    export default {
        data() {
            return {
                geohash: '', //geohash位置信息
                goodId: null, //商品id值
                showLoading: true, //显示加载动画
                goodDetailData: null, //商铺详情
                windowHeight: null, //屏幕的高度
                elLeft: 0, //当前点击加按钮在网页中的绝对top值
                elBottom: 0, //当前点击加按钮在网页中的绝对left值
                userId: '',
                imgBaseUrl,
            }
        },
        created() {
            // this.geohash = this.$route.query.geohash;
        },
        activated() {
            this.initData();
            this.windowHeight = window.innerHeight;
        },
        beforeDestroy() {
            // this.foodScroll.removeEventListener('scroll', )
        },
        mixins: [loadMore, getImgPath],
        components: {
            loading,
           // ratingStar,
           // buyCart,
            headTop,
        },
        computed: {
            ...mapState([
                'latitude', 'longitude', 'cartList','goodDetailData',
            ]),
        },
        methods: {
            ...mapMutations([
               ]),
            //初始化时获取基本数据
            async initData() {
                //获取商品信息
                this.goodId = this.$route.query.id;
                this.goodDetailData = await goodDetails(this.goodId);
                console.log(this.goodDetailData)
                //隐藏加载动画
                this.hideLoading();
            },

            //隐藏动画
            hideLoading() {
                this.showLoading = false;
            },

            goback() {
                this.$router.go(-1);
            }
        },
        watch: {
            //showLoading变化时说明组件已经获取初始化数据，在下一帧nextTick进行后续操作
            showLoading: function (value) {
                if (!value) {
                    this.$nextTick(() => {
                    })
                }
            },
        }
    }
</script>

<style lang="scss" scoped>
    @import 'src/style/mixin';

    @keyframes mymove {
        0% {
            transform: scale(1)
        }
        25% {
            transform: scale(.8)
        }
        50% {
            transform: scale(1.1)
        }
        75% {
            transform: scale(.9)
        }
        100% {
            transform: scale(1)
        }
    }

    @-moz-keyframes mymove {
        0% {
            transform: scale(1)
        }
        25% {
            transform: scale(.8)
        }
        50% {
            transform: scale(1.1)
        }
        75% {
            transform: scale(.9)
        }
        100% {
            transform: scale(1)
        }
    }

    @-webkit-keyframes mymove {
        0% {
            transform: scale(1)
        }
        25% {
            transform: scale(.8)
        }
        50% {
            transform: scale(1.1)
        }
        75% {
            transform: scale(.9)
        }
        100% {
            transform: scale(1)
        }
    }

    @-o-keyframes mymove {
        0% {
            transform: scale(1)
        }
        25% {
            transform: scale(.8)
        }
        50% {
            transform: scale(1.1)
        }
        75% {
            transform: scale(.9)
        }
        100% {
            transform: scale(1)
        }
    }

    .sellerinfo {
        white-space: nowrap;
        padding: 0.1em;
        clear: right;

        li {
            display: inline-block;
            white-space: nowrap;
        }

        .selleravatar {
            display: inline-block;
            width: 1.2em;
            height: 1.2em;
            overflow: hidden;
            margin-left: 0.2em;
            border-radius: 0.15rem;
            img{

            }
        }

        .sellername {
            @include font(0.75em, 0.75rem, 'PingFangSC-Regular');
            margin-bottom: 0.3em;
        }
    }

    .goodinfo {
        text-align: left;
        list-style: none;
        margin: 0.4em;

        .goodprice {
            display: inline-block;
            float: left;
            color: red !important;
            width: 100%;

            span {
                color: #dc1b14;
                @include font(1.2rem, 1.2rem, 'PingFangSC-Regular');
            }
        }

        .gooddesc {
            display: inline-block;
            @include font(0.62em, 0.8rem, 'PingFangSC-Regular');
            margin-bottom: 0.3em;
        }
    }

    .good_image_container {
        border-radius: 0.2rem;
        margin: 0.4em;
        overflow: hidden;

        .goodimage {
            display: block;
            margin-right: 0.4rem;
            height: 15rem;
            width: 100%;
        }
    }

    hr {
        height: 0.1em;
        border: none;
        border-top: 0.01em solid #9f9f9ff9;
        width: 14em;
        display: block;
        clear: right;
        margin-bottom: 0em !important;
        margin-top: 0em !important;
    }

    .buyfoot {
        background-color: #fff;
        position: fixed;
        z-index: 100;
        left: 0;
        right: 0;
        bottom: 0;
        @include wh(100%, 1.95rem);
        display: flex;
        box-shadow: 0 -0.026667rem 0.053333rem rgba(0, 0, 0, .1);

        img {
            @include wh(1rem, 1rem);
            margin-top: 0.28em;
            margin-left: 0.2em;
        }

        .buybutton {
            width: 10.3em;
            height: 1.2em;
            margin-left: 24em;
            margin-top: 1em;
            @include font(0.52em, 1.04rem, 'PingFangSC-Regular');

            span {
                display: inline-block;
                background-color: red;
                color: #ffffff;
                border-radius: 0.8em;
                width: 3.7em;
                text-align: center;
                height: 1.9em;

            }
        }
    }

    .good_back_svg_container {
        position: fixed;
        @include wh(100%, 100%);

        img {
            @include wh(100%, 100%);
        }
    }

    .goodsdetail_container {
        padding-top: 1.95rem;
    }

    .screen_cover {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        background-color: rgba(0, 0, 0, .3);
        z-index: 11;
    }

    .fade-enter-active, .fade-leave-active {
        transition: opacity .5s;
    }

    .fade-enter, .fade-leave-active {
        opacity: 0;
    }

    .fade-choose-enter-active, .fade-choose-leave-active {
        transition: opacity .5s;
    }

    .fade-choose-leave, .fade-choose-leave-active {
        display: none;
    }

    .fade-choose-enter, .fade-choose-leave-active {
        opacity: 0;
    }

    .router-slid-enter-active, .router-slid-leave-active {
        transition: all .4s;
    }

    .router-slid-enter, .router-slid-leave-active {
        transform: translate3d(2rem, 0, 0);
        opacity: 0;
    }

    .toggle-cart-enter-active, .toggle-cart-leave-active {
        transition: all .3s ease-out;
    }

    .toggle-cart-enter, .toggle-cart-leave-active {
        transform: translateY(100%);
    }

</style>
